package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.VO.BrandListVO;
import cn.tedu.csmall.product.pojo.VO.BrandStandardVO;
import cn.tedu.csmall.product.pojo.VO.CategoryListVO;
import cn.tedu.csmall.product.pojo.dto.BrandAddNewDTO;
import cn.tedu.csmall.product.pojo.dto.BrandUpdateDTO;
import cn.tedu.csmall.product.pojo.dto.CategoryAddNewDTO;
import cn.tedu.csmall.product.service.IBrandService;
import cn.tedu.csmall.product.service.ICategoryService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/brands")
@Api(tags = "品牌管理")
public class BrandController {

    @Autowired
    IBrandService brandService;

    @PostMapping("/add-new")
    @ApiOperation("添加品牌")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addNew(BrandAddNewDTO brandAddNewDTO){
        log.debug("开始处理添加品牌业务");
        brandService.addNew(brandAddNewDTO);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("根据ID删除品牌")
    @ApiOperationSupport(order = 200)
    public JsonResult<Void> delete(@Range(min = 1,max = 10000,message = "删除品牌失败，品牌ID非法！") @PathVariable Long id){
        log.debug("开始处理删除品牌的请求，接收到的参数是：{}",id);
        brandService.deleteById(id);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/update")
    @ApiOperation("修改品牌")
    @ApiOperationSupport(order = 300)
    public JsonResult<Void> update(@PathVariable Long id, BrandUpdateDTO brandUpdateDTO){
        brandService.update(id,brandUpdateDTO);
        return JsonResult.ok();
    }

//    @PostMapping("/{id:[0-9]+}/enable")
//    @ApiOperation("启用类别")
//    @ApiOperationSupport(order = 301)
//    public JsonResult<Void> setEnable(@PathVariable Long id){
//        log.debug("开始处理修改【启用项】业务请求，修改的对象是：{}",id);
//        categoryService.setEnable(id);
//        return JsonResult.ok();
//    }

//    @PostMapping("/{id:[0-9]+}/disable")
//    @ApiOperation("禁用类别")
//    @ApiOperationSupport(order = 302)
//    public JsonResult<Void> setDisable(@PathVariable Long id){
//        log.debug("开始处理修改【禁用项】业务请求，修改的对象是：{}",id);
//        categoryService.setDisable(id);
//        return JsonResult.ok();
//    }

//    @PostMapping("/{id:[0-9]+}/display")
//    @ApiOperation("显示导航栏")
//    @ApiOperationSupport(order = 301)
//    public JsonResult<Void> setDisplay(@PathVariable Long id){
//        log.debug("开始处理修改【启用项】业务请求，修改的对象是：{}",id);
//        categoryService.setEnable(id);
//        return JsonResult.ok();
//    }
//
//    @PostMapping("/{id:[0-9]+}/doNotDisplay")
//    @ApiOperation("不显示导航栏")
//    @ApiOperationSupport(order = 302)
//    public JsonResult<Void> doNotDisplay(@PathVariable Long id){
//        log.debug("开始处理修改【禁用项】业务请求，修改的对象是：{}",id);
//        categoryService.setDisable(id);
//        return JsonResult.ok();
//    }



    @GetMapping("/{id:[0-9]+}/select")
    @ApiOperation("查询品牌")
    @ApiOperationSupport(order = 300)
    public JsonResult<BrandStandardVO> getStandard(@PathVariable Long id){
        BrandStandardVO standardById = brandService.getStandardById(id);
        return JsonResult.ok(standardById);
    }




    @GetMapping( "/list")
    @ApiOperation("查询品牌列表")
    @ApiOperationSupport(order = 400)
    public JsonResult<List<BrandListVO>> list(){
        List<BrandListVO> lists = brandService.getList();
        return JsonResult.ok(lists);
    }
}